package com.hmob.hmdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.hmob.hmsdk.ads.AdError;
import com.hmob.hmsdk.ads.interstitial.HMInterstitial;
import com.hmob.hmsdk.ads.interstitial.InterstitialListener;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private HMInterstitial interstitialAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        findViewById(R.id.bt_splash).setOnClickListener(this);
        findViewById(R.id.bt_banner).setOnClickListener(this);
        findViewById(R.id.bt_interstitial).setOnClickListener(this);
        findViewById(R.id.bt_native).setOnClickListener(this);
        findViewById(R.id.bt_floating).setOnClickListener(this);
        findViewById(R.id.bt_text_link).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_splash:
                startActivity(new Intent(MainActivity.this, SplashBottomActivity.class));
                break;
            case R.id.bt_banner:
                startActivity(new Intent(MainActivity.this, BannerActivity.class));
                break;
            case R.id.bt_native:
                startActivity(new Intent(MainActivity.this, NativeActivity.class));
                break;
            case R.id.bt_floating:
                startActivity(new Intent(MainActivity.this, FloatingActivity.class));
                break;
            case R.id.bt_interstitial:
                showInterstitial();
                break;
            case R.id.bt_text_link:
                startActivity(new Intent(MainActivity.this, TextLinkActivity.class));
                break;
            default:
                break;
        }
    }

    private void showInterstitial() {
        //展示广告，仅在onADReceived()回调方法发生后调用才会生效
        interstitialAd = new HMInterstitial(Constants.ADID_INTERSTITIAL, new InterstitialListener() {
            @Override
            public void onNoAD(AdError adError) {
                Log.e("HMInterstitial", adError.getErrorMessage());
            }

            @Override
            public void onADReceived() {
                //展示广告，仅在onADReceived()回调方法发生后调用才会生效
                interstitialAd.show();
                Log.i("HMInterstitial", "onADReceived");
            }

            @Override
            public void onADExposure() {
                Log.i("HMInterstitial", "onADExposure");
            }

            @Override
            public void onADClicked() {
                Log.i("HMInterstitial", "onADClicked");
            }
        });
        //请求插屏广告，每次重新请求都可以调用此方法
        interstitialAd.load(MainActivity.this);
    }
}
